#include "gtkapplicationprivate.h"
#include "gtkmodelmenu-quartz.h"
-#include "gtkmessagedialog.h"
-#include <glib/gi18n-lib.h>
#import <Cocoa/Cocoa.h>
typedef struct
GSList *inhibitors;
gint quit_inhibit;
guint next_cookie;
+ NSObject *delegate;
} GtkApplicationImplQuartz;
G_DEFINE_TYPE (GtkApplicationImplQuartz, gtk_application_impl_quartz, GTK_TYPE_APPLICATION_IMPL)
-/* OS X implementation copied from EggSMClient, but simplified since
- * it doesn't need to interact with the user.
- */
-
-static gboolean
-idle_will_quit (gpointer user_data)
+@interface GtkApplicationQuartzDelegate : NSObject
{
- GtkApplicationImplQuartz *quartz = user_data;
+ GtkApplicationImplQuartz *quartz;
+}
- if (quartz->quit_inhibit == 0)
- g_application_quit (G_APPLICATION (quartz->impl.application));
- else
- {
- GtkApplicationQuartzInhibitor *inhibitor;
- GSList *iter;
- GtkWidget *dialog;
-
- for (iter = quartz->inhibitors; iter; iter = iter->next)
- {
- inhibitor = iter->data;
- if (inhibitor->flags & GTK_APPLICATION_INHIBIT_LOGOUT)
- break;
- }
- g_assert (inhibitor != NULL);
-
- dialog = gtk_message_dialog_new (inhibitor->window,
- GTK_DIALOG_MODAL,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_OK,
- _("%s cannot quit at this time:\n\n%s"),
- g_get_application_name (),
- inhibitor->reason);
- g_signal_connect_swapped (dialog,
- "response",
- G_CALLBACK (gtk_widget_destroy),
- dialog);
- gtk_widget_show_all (dialog);
- }
+- (id)initWithImpl:(GtkApplicationImplQuartz*)impl;
+- (NSApplicationTerminateReply) applicationShouldTerminate:(NSApplication *)sender;
+@end
- return G_SOURCE_REMOVE;
+@implementation GtkApplicationQuartzDelegate
+-(id)initWithImpl:(GtkApplicationImplQuartz*)impl
+{
+ [super init];
+ quartz = impl;
+ return self;
}
-static pascal OSErr
-quit_requested (const AppleEvent *aevt,
- AppleEvent *reply,
- long refcon)
+-(NSApplicationTerminateReply) applicationShouldTerminate:(NSApplication *)sender
{
- GtkApplicationImplQuartz *quartz = GSIZE_TO_POINTER ((gsize)refcon);
-
- /* Don't emit the "quit" signal immediately, since we're
- * called from a weird point in the guts of gdkeventloop-quartz.c
+ /* We have no way to give our message other than to pop up a dialog
+ * ourselves, which we should not do since the OS will already show
+ * one when we return NSTerminateNow.
+ *
+ * Just let the OS show the generic message...
*/
- g_idle_add_full (G_PRIORITY_DEFAULT, idle_will_quit, quartz, NULL);
-
- return quartz->quit_inhibit == 0 ? noErr : userCanceledErr;
+ return quartz->quit_inhibit == 0 ? NSTerminateNow : NSTerminateCancel;
}
+@end
static void
gtk_application_impl_quartz_menu_changed (GtkApplicationImplQuartz *quartz)
GtkApplicationImplQuartz *quartz = (GtkApplicationImplQuartz *) impl;
if (register_session)
- AEInstallEventHandler (kCoreEventClass, kAEQuitApplication,
- NewAEEventHandlerUPP (quit_requested),
- (long)GPOINTER_TO_SIZE (quartz), false);
+ {
+ quartz->delegate = [[GtkApplicationQuartzDelegate alloc] initWithImpl:quartz];
+ [NSApp setDelegate: quartz->delegate];
+ }
gtk_application_impl_quartz_menu_changed (quartz);
gtk_quartz_clear_main_menu ();
+ if (quartz->delegate)
+ {
+ [quartz->delegate release];
+ quartz->delegate = NULL;
+ }
+
g_slist_free_full (quartz->inhibitors, (GDestroyNotify) gtk_application_quartz_inhibitor_free);
quartz->inhibitors = NULL;
}